package com.sias.controller;


import com.sias.common.result.Result;
import com.sias.common.result.ResultCodeEnum;
import com.sias.entity.dto.CourseInfoDto;
import com.sias.entity.vo.OneCourseVo;
import com.sias.service.CourseService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping (value = "/course")
public class CouresController {
    @Autowired
    private CourseService courseService;

    @ApiOperation(value = "新增课程")
    @PostMapping("/listAllCourse")
    public Result listAllCourse(){
        List<OneCourseVo> allCourse= courseService.listAll();
        return Result.build(allCourse,ResultCodeEnum.SUCCESS);
    }



    @ApiOperation(value = "新增课程")
    @PostMapping("/save-course-info")
    public Result saveCourseInfo(
            @ApiParam(name = "CourseInfoDto", value = "课程基本信息", required = true)
        @RequestBody CourseInfoDto courseInfoDto){
        String courseId = courseService.saveCourseInfo(courseInfoDto);
        if(!StringUtils.isEmpty(courseId)){
            return Result.build(courseId,ResultCodeEnum.SUCCESS);
        }else{
            return Result.build(null,ResultCodeEnum.DATA_ERROR);
        }
    }




}
